#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define ERROR_CHECK(ret, num, msg) \
    {                              \
        if (ret == num)            \
        {                          \
            perror(msg);           \
            exit(1);               \
        }                          \
    }
int main(int argc, char *argv[])
{
    int fd = open("openSysCal.txt", O_CREAT | O_RDWR , 0664);
    ERROR_CHECK(-1, fd, "open");
    int ret = lseek(fd,0L,SEEK_END);
    printf("%dbyte\n",ret);
    lseek(fd,0L,SEEK_SET);
    char buf[16] = {0};
    for (size_t i = 0; i < 16; i++)
    {
        buf[i] = 'A' + i;
    }

     ret = write(fd, buf, sizeof(buf));
    ERROR_CHECK(-1, ret, "write");
    memset(buf, 0, sizeof(buf));
    ret = lseek(fd,0L,SEEK_SET);
    
    ret = read(fd, buf, sizeof(buf) - 1);
    ERROR_CHECK(-1, ret, "read");
     puts(buf);
    ///////////
    char buf2[16] = {0};
    int fd2 = open("openSysCal.txt", O_RDONLY);
    ret = read(fd2, buf2, sizeof(buf) - 1);
    ERROR_CHECK(-1, ret, "read");
    puts(buf2);
    return 0;
}
